package com.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 实现WebMvcConfigurer接口，扩展MVC功能
 */
@Configuration
@EnableWebMvc
public class MyMVCconfig implements WebMvcConfigurer {
    @Autowired
    private MyInterceptor myInterceptor;

    // 添加拦截器管理
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        registry.addInterceptor(myInterceptor)
                .addPathPatterns("/**")
                //不拦截登录，上传下载文件端口
                .excludePathPatterns("/ueUploadController/**","/toRegister","/admin/toLogin","/admin/login","/delete/**","/update/**","/get/**","/toLogin","/login","/logout","/toUpload","/uploadFile","/download","/toDownload","/static/**","/register")
                .excludePathPatterns("/login.html");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        //放开resources/static下的所有资源拦截
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
}

